package com.ncloud.crm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ncloud.crm.entity.BsPublicCloud;

/**
 * Created by shiqiang on 2017/4/17.
 */
@Mapper
public interface BsPublicCloudMapper {
    @Select(value = { "select * from bs_public_cloud where cloud_id = #{cloudId} and now() between begin_date and end_date" })
    @Results({ @Result(column = "node_id", property = "nodeId"), @Result(column = "cloud_id", property = "cloudId"),
            @Result(column = "cloud_type", property = "cloudType"),@Result(column="gateway_ip",property="gatewayIp"),
            @Result(column="inter_area",property="interArea"),
            @Result(column="gateway_bgp_as",property="gatewayBgpAs"),@Result(column="gateway_port",property="gatewayPort"),
            @Result(column="outer_vlan",property="outerVlan"),@Result(column="inner_vlan",property="innerVlan"),
            @Result(column="begin_date",property="beginDate"),@Result(column="end_date",property="endDate"),
            @Result(column="update_time",property="updateTime"),@Result(column="update_user",property="updateUser")})
    public BsPublicCloud getNodeCloudInfoByPk(Long cloudId);

    @Insert("insert into bs_public_cloud(cloud_id, node_id, cloud_type, inter_area, gateway_ip,"
    		+ " gateway_bgp_as, gateway_port, outer_vlan, inner_vlan, begin_date, end_date, update_time, update_user)"
    		+ " values(#{cloudId}, #{nodeId}, #{cloudType}, #{interArea}, #{gatewayIp},"
    		+ " #{gatewayBgpAs}, #{gatewayPort}, #{outerVlan}, #{innerVlan}, #{beginDate}, #{endDate}, #{updateTime}, #{updateUser})")
	public int insertNodeCloud(BsPublicCloud node);

    @Update("update bs_public_cloud set cloud_type=#{cloudType},gateway_ip=#{gatewayIp},inter_area=#{interArea},"
    		+ " gateway_bgp_as=#{gatewayBgpAs},gateway_port=#{gatewayPort},outer_vlan=#{outerVlan},inner_vlan=#{innerVlan},"
    		+ " end_date=#{endDate},update_time=#{updateTime},update_user=#{updateUser}"
    		+ " where node_id=#{nodeId} and cloud_id=#{cloudId} and begin_date = #{beginDate}")
	public int updateNodeCloud(BsPublicCloud bsPublicCloud);

    @Select(value = { "select * from bs_public_cloud where node_id = #{nodeId} and now() between begin_date and end_date" })
    @Results({ @Result(column = "node_id", property = "nodeId"), @Result(column = "cloud_id", property = "cloudId"),
            @Result(column = "cloud_type", property = "cloudType"),@Result(column="gateway_ip",property="gatewayIp"),
            @Result(column="inter_area",property="interArea"),
            @Result(column="gateway_bgp_as",property="gatewayBgpAs"),@Result(column="gateway_port",property="gatewayPort"),
            @Result(column="outer_vlan",property="outerVlan"),@Result(column="inner_vlan",property="innerVlan"),
            @Result(column="begin_date",property="beginDate"),@Result(column="end_date",property="endDate"),
            @Result(column="update_time",property="updateTime"),@Result(column="update_user",property="updateUser")})
	public List<BsPublicCloud> getNodeCloudByNodeId(Long nodeId);

    @Select(value = { "select * from bs_o_work_public_cloud where node_id = #{nodeId} and now() between begin_date and end_date" })
    @Results({ @Result(column = "node_id", property = "nodeId"), @Result(column = "cloud_id", property = "cloudId"),
            @Result(column = "cloud_type", property = "cloudType"),@Result(column="gateway_ip",property="gatewayIp"),
            @Result(column="inter_area",property="interArea"),
            @Result(column="gateway_bgp_as",property="gatewayBgpAs"),@Result(column="gateway_port",property="gatewayPort"),
            @Result(column="outer_vlan",property="outerVlan"),@Result(column="inner_vlan",property="innerVlan"),
            @Result(column="begin_date",property="beginDate"),@Result(column="end_date",property="endDate"),
            @Result(column="work_id",property="workId"),@Result(column="modify_tag",property="modifyTag"),
            @Result(column="update_time",property="updateTime"),@Result(column="update_user",property="updateUser")})
	public List<BsPublicCloud> getBsNodeCloudByNodeId(Long nodeId);
}
